#pragma once

#pragma warning(push)
#pragma warning (disable : 4661)

#include "Hellfire_Common.h"

namespace Hellfire
{
    template <typename T>
	class Singleton
    {
	private:

		Singleton(const Singleton<T> &);

		Singleton& operator=(const Singleton<T> &);
    
	protected:

        static T* m_spSingleton;

    public:

		Singleton(void)
		{
			assert(! m_spSingleton);
#if defined( _MSC_VER ) && _MSC_VER < 1200	 
			int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
			m_spSingleton = (T*)((int)this + offset);
#else
			m_spSingleton = static_cast<T*>(this);
#endif
		}

        ~Singleton(void)
		{  
			assert(m_spSingleton);  
			m_spSingleton = NULL;
		}

        static T* GetSingletonPtr(void)
		{ 
			return m_spSingleton;
		}
    };
}

#pragma warning(pop)